
#include "Camera.h"

Camera* Camera::GetInstance()
{
	static Camera pCamera;
	return &pCamera;
}

bool Camera::GetFollowing()
{
	return bIsFollowing;
}

SGD::Point Camera::GetPosition()
{
	return position;
}

SGD::Point Camera::GetDestination()
{
	return destination;
}

float Camera::GetSpeed()
{
	return fSpeed;
}

float Camera::GetMaxSpeed()
{
	return fMaxSpeed;
}

void Camera::SetFollowing(bool follow)
{
	bIsFollowing = follow;
}

void Camera::SetPosition(SGD::Point point)
{
	position = point;
}

void Camera::SetDestination(SGD::Point point)
{
	destination = point;
}

void Camera::SetSpeed(float speed)
{
	fSpeed = speed;
}

void Camera::SetMaxSpeed(float speed)
{
	fMaxSpeed = speed;
}

int Camera::Update(float dt)
{
	if (!GetFollowing()) // Is Not Following Player
	{
		SGD::Vector v = SGD::Vector(GetDestination() - GetPosition());
		if (v.ComputeLength() < 0.05f)
		{
			SetFollowing(true);
			return 0;
		}

		v.Normalize();
		v *= GetSpeed();
		SetSpeed(GetSpeed() + 0.03f);
		if (GetSpeed() > GetMaxSpeed())
			SetSpeed(GetMaxSpeed());

		SGD::Point newPosition = SGD::Point(GetPosition().x + (v.x * dt), GetPosition().y + (v.y * dt));
		SetPosition(newPosition);
	}
	return 0;
}